package database

import (
	"fmt"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)

var db *gorm.DB

func init() {
	Db, err := gorm.Open(sqlite.Open("./config/database.db"), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	err = Db.AutoMigrate(
		&User{},
		&Sort{},
		&ArticleContent{},
	)
	if err != nil {
		fmt.Println("迁移数据库失败：", err)
	} else {
		fmt.Println("初始化数据库完成")
	}
	db = Db
}
